package com.ruoyi.web.controller.gcgl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ConvertUpMoneyUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DecimalCalculateUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gcgl.domain.GcCustomer;
import com.ruoyi.gcgl.domain.GcFk;
import com.ruoyi.gcgl.domain.GcFkfp;
import com.ruoyi.gcgl.domain.GcFkitem;
import com.ruoyi.gcgl.domain.GcProject;
import com.ruoyi.gcgl.domain.GcProjectCbpj;
import com.ruoyi.gcgl.domain.GcProjectCbpjitem;
import com.ruoyi.gcgl.domain.GcProjectExeVo;
import com.ruoyi.gcgl.domain.GcProjectFlow;
import com.ruoyi.gcgl.domain.GcProjectGroup;
import com.ruoyi.gcgl.domain.GcProjectOther;
import com.ruoyi.gcgl.domain.GcProjectQrsk;
import com.ruoyi.gcgl.domain.GcProjectQtfy;
import com.ruoyi.gcgl.domain.GcProjectQtwj;
import com.ruoyi.gcgl.domain.GcProjectSbclht;
import com.ruoyi.gcgl.domain.GcProjectSgazht;
import com.ruoyi.gcgl.domain.GcProjectSjtz;
import com.ruoyi.gcgl.domain.GcProjectSqkp;
import com.ruoyi.gcgl.domain.GcProjectSqkpfp;
import com.ruoyi.gcgl.domain.GcProjectUpVo;
import com.ruoyi.gcgl.domain.GcProjectXmxq;
import com.ruoyi.gcgl.domain.GcProjectZjbj;
import com.ruoyi.gcgl.domain.GcSupply;
import com.ruoyi.gcgl.mapper.GcSendTipMapper;
import com.ruoyi.gcgl.service.IGcCustomerService;
import com.ruoyi.gcgl.service.IGcFkService;
import com.ruoyi.gcgl.service.IGcFkfpService;
import com.ruoyi.gcgl.service.IGcFkitemService;
import com.ruoyi.gcgl.service.IGcProjectCbpjService;
import com.ruoyi.gcgl.service.IGcProjectCbpjitemService;
import com.ruoyi.gcgl.service.IGcProjectFlowService;
import com.ruoyi.gcgl.service.IGcProjectGroupService;
import com.ruoyi.gcgl.service.IGcProjectOtherService;
import com.ruoyi.gcgl.service.IGcProjectQrskService;
import com.ruoyi.gcgl.service.IGcProjectQtfyService;
import com.ruoyi.gcgl.service.IGcProjectQtwjService;
import com.ruoyi.gcgl.service.IGcProjectSbclhtService;
import com.ruoyi.gcgl.service.IGcProjectService;
import com.ruoyi.gcgl.service.IGcProjectSgazhtService;
import com.ruoyi.gcgl.service.IGcProjectSjtzService;
import com.ruoyi.gcgl.service.IGcProjectSqkpService;
import com.ruoyi.gcgl.service.IGcProjectSqkpfpService;
import com.ruoyi.gcgl.service.IGcProjectXmxqService;
import com.ruoyi.gcgl.service.IGcProjectZjbjService;
import com.ruoyi.gcgl.service.IGcSendTipService;
import com.ruoyi.gcgl.service.IGcSupplyService;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.web.controller.tool.AliyunSmsUtils;

/**
 * 项目立项Controller
 * 
 * @author ruoyi
 * @date 2022-11-17
 */
@Controller
@RequestMapping("/gcgl/project")
public class GcProjectController extends BaseController
{
    private String prefix = "gcgl/project";
    private String gsmc = "湖北鄂能电力建设有限公司";
    private String sbh = "91420106MA7H9PKY8C";

    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private IGcProjectService gcProjectService;
    @Autowired
    private IGcCustomerService gcCustomerService;
    @Autowired
    private IGcProjectFlowService gcProjectFlowService;
    @Autowired
    private IGcFkService gcFkService;
    @Autowired
    private IGcFkitemService gcFkitemService;
    //成本
    @Autowired
    private IGcProjectCbpjService gcProjectCbpjService;
    @Autowired
    private IGcProjectCbpjitemService gcProjectCbpjitemService;
    //其他文件
    @Autowired
    private IGcProjectQtwjService gcProjectQtwjService;
    //设计图纸
    @Autowired
    private IGcProjectSjtzService gcProjectSjtzService;
    //造价报价
    @Autowired
    private IGcProjectZjbjService gcProjectZjbjService;
    //项目详情
    @Autowired
    private IGcProjectXmxqService gcProjectXmxqService;
    @Autowired
    private IGcProjectQtfyService gcProjectQtfyService;
    @Autowired
    private IGcFkfpService gcFkfpService;
    @Autowired
    private IGcSupplyService gcSupplyService;
    @Autowired
    private IGcProjectQrskService gcProjectQrskService;
    @Autowired
    private IGcProjectSqkpService gcProjectSqkpService;
    @Autowired
    private IGcSendTipService gcSendTipService;
    @Autowired
    private IGcProjectSbclhtService gcProjectSbclhtService;
    @Autowired
    private IGcProjectSgazhtService gcProjectSgazhtService;
    @Autowired
    private IGcProjectOtherService gcProjectOtherService;
    @Autowired
    private IGcProjectSqkpfpService gcProjectSqkpfpService;
    @Autowired
    private ISysDictDataService sysDictDataService;
    @Autowired
    private IGcProjectGroupService gcProjectGroupService;
    @Autowired
    private GcSendTipMapper gcSendTipMapper;
    
    @GetMapping("/home")
    public String home(ModelMap mmap){
    	GcProjectFlow gcProjectFlow = new GcProjectFlow();
    	gcProjectFlow.setSjtz(0);
    	mmap.put("gcProjectFlowObj", gcProjectFlow);
        return "gcgl/flow_cart/flow_cart";
    }
    
    @GetMapping("/editHome/{id}")
    public String editHome(ModelMap mmap,@PathVariable("id") Long id){
    	GcProjectFlow gcProjectFlow = new GcProjectFlow();
    	gcProjectFlow.setDeleteFlag(1);
    	gcProjectFlow.setGcProjectid(id);
    	List<GcProjectFlow> flowlis = gcProjectFlowService.selectGcProjectFlowList(gcProjectFlow);
    	mmap.put("gcProjectFlowObj", flowlis.get(0));
        return "gcgl/flow_cart/flow_cart";
    }

    @RequiresPermissions("gcgl:project:view")
    @GetMapping()
    public String project(){
        return prefix + "/project";
    }

    /**
     * 查询项目立项列表
     */
    @RequiresPermissions("gcgl:project:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GcProject gcProject)
    {
        startPage();
        gcProject.setDeleteFlag(1);
        if(getSysUser().isShow43R(getUserId())){
        	gcProject.setOwner(getLoginName());
        }
        List<GcProject> list = gcProjectService.selectGcProjectList(gcProject);
        return getDataTable(list);
    }

    /**
     * 导出项目立项列表
     */
    @RequiresPermissions("gcgl:project:export")
    @Log(title = "项目立项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GcProject gcProject)
    {
    	gcProject.setDeleteFlag(1);
    	if(getSysUser().isShow()){
    		gcProject.setOwner(getLoginName());
    	}
        List<GcProject> list = gcProjectService.selectGcProjectList(gcProject);
        ExcelUtil<GcProject> util = new ExcelUtil<GcProject>(GcProject.class);
        return util.exportExcel(list, "项目立项数据");
    }

    /**
     * 新增项目立项
     */
    @GetMapping("/add")
    public String add(ModelMap mmap){
    	
    	GcCustomer gcCustomer = new GcCustomer();
    	gcCustomer.setDeleteFlag(1);
    	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
    	mmap.put("clis", gcCustomerlis);
    	
    	GcProjectGroup gcProjectGroup = new GcProjectGroup();
    	gcProjectGroup.setDeleteFlag(1);
    	List<GcProjectGroup> grouplis = gcProjectGroupService.selectGcProjectGroupList(gcProjectGroup);
    	mmap.put("glis", grouplis);
    	
        return prefix + "/add";
    }

    /**
     * 新增保存项目立项
     */
    @RequiresPermissions("gcgl:project:add")
    @Log(title = "项目立项", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public synchronized AjaxResult addSave(GcProject gcProject){
    	
    	SimpleDateFormat sdy = new SimpleDateFormat("yyyy");
		SimpleDateFormat sdm = new SimpleDateFormat("MM");
		int year = Integer.parseInt(sdy.format(new Date()));
		int month = Integer.parseInt(sdm.format(new Date()));
		GcProject newObj = new GcProject();
		newObj.setDeleteFlag(1);
		newObj.setCreateAt(DateUtils.getFisrtDayOfMonth(year, 1));
		newObj.setUpdateAt(DateUtils.getLastDayOfMonth(year, 12));
		List<GcProject> lisCount = gcProjectService.selectGcProjectList(newObj);
    	
//    	gcProject.setOrderNo(ReturnUUID.getOrderNo("HT"));
		String no = String.format("%02d", lisCount.size()+1);
		gcProject.setOrderNo(year+"-"+no);
		gcProject.setJsNo(year+"-"+month);
    	gcProject.setStatus(0);
    	gcProject.setOwner(getLoginName());
    	gcProject.setDeleteFlag(1);
    	gcProject.setCreateAt(new Date());
    	gcProject.setUpdateAt(new Date());
    	gcProject.setCreateUser(getLoginName());
    	gcProject.setUpdateUser(getLoginName());
    	
    	SysUser user = sysUserService.selectUserByLoginName(gcProject.getOwner());
    	gcProject.setSpr(user.getZjsjName());//2024年12月30日修改，增加分管领导审批
    	
    	gcProjectService.insertGcProject(gcProject);
    	
    	GcProjectFlow gcProjectFlow = new GcProjectFlow();
    	gcProjectFlow.setGcProjectid(gcProject.getId());
    	gcProjectFlow.setSjtz(0);
    	gcProjectFlow.setQtwj(0);
    	gcProjectFlow.setCbyg(0);
    	gcProjectFlow.setZjbj(0);
    	gcProjectFlow.setHtxq(0);
    	gcProjectFlow.setXmps(0);
    	gcProjectFlow.setXmqtfy(0);
    	gcProjectFlow.setDeleteFlag(1);
    	gcProjectFlow.setCreateAt(new Date());
    	gcProjectFlow.setUpdateAt(new Date());
    	gcProjectFlow.setCreateUser(getLoginName());
    	gcProjectFlow.setUpdateUser(getLoginName());
    	gcProjectFlowService.insertGcProjectFlow(gcProjectFlow);

    	//取消中标服务费
//    	if(gcProject.getZongje()!=null && !gcProject.getZongje().equals("") && gcProject.getZongje()!=0.0){
//    		addQtfk(gcProject);
//    	}
    	
    	//发送消息通知
//    	gcSendTipService.sendTipXm("xmht", gcProject.getName(), gcProject.getOrderNo(), 
//    			gcProject.getCreateUser(), DateUtils.dateTime(gcProject.getCreateAt()), 
//    			gcProject.getStatus().toString(), null, gcProject.getId().toString());
    	
    	try {
    			SysUser user1 = sysUserService.selectUserById(user.getZjsjId());
    			String phonenumber = user1.getPhonenumber();//分管领导
    			AliyunSmsUtils.returnSmsTz(phonenumber);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
    	
        return toAjax(1);
    }
    
    /**
     * 项目保证金
     * @param gcProject
     */
    private void addQtfk(GcProject gcProject){
    	GcCustomer gcCustomer = new GcCustomer();
    	gcCustomer.setDeleteFlag(1);
    	gcCustomer.setName(gcProject.getCustomerName());
    	List<GcCustomer> culis = gcCustomerService.selectGcCustomerList(gcCustomer);
    	
    	//项目保证金
    	GcProjectQtfy gcProjectQtfy = new GcProjectQtfy();
    	gcProjectQtfy.setGcProjectid(gcProject.getId());
    	gcProjectQtfy.setOrderNo(gcProject.getOrderNo());
    	gcProjectQtfy.setName(gcProject.getName());
    	if(culis!=null && culis.size()>0){
    		gcProjectQtfy.setSupplyId(culis.get(0).getId());
    	}
    	gcProjectQtfy.setSupplyName(gcProject.getCustomerName());
    	gcProjectQtfy.setZongje(gcProject.getZongje());//保证金
    	gcProjectQtfy.setStatus(0);
    	gcProjectQtfy.setDeleteFlag(1);
    	gcProjectQtfy.setCreateUser(getLoginName());
    	gcProjectQtfy.setUpdateUser(getLoginName());
    	gcProjectQtfy.setCreateAt(new Date());
    	gcProjectQtfy.setUpdateAt(new Date());
    	gcProjectQtfyService.insertGcProjectYbfy(gcProjectQtfy);
    	
    	GcProjectFlow gcProjectFlow = new GcProjectFlow();
    	gcProjectFlow.setXmqtfy(1);
    	gcProjectFlow.setGcProjectid(gcProject.getId());
    	gcProjectFlowService.updateGcProjectFlow(gcProjectFlow);
    }
    
    private void updateQtfk(GcProject gcProject){
    	//项目保证金
    	GcProjectQtfy gcProjectQtfy = new GcProjectQtfy();
    	gcProjectQtfy.setDeleteFlag(1);
    	gcProjectQtfy.setGcProjectid(gcProject.getId());
    	List<GcProjectQtfy> qtfylis = gcProjectQtfyService.selectGcProjectYbfyList(gcProjectQtfy);
    	
    	if(qtfylis!=null && qtfylis.size()>0){
    		GcCustomer gcCustomer = new GcCustomer();
        	gcCustomer.setDeleteFlag(1);
        	gcCustomer.setName(gcProject.getCustomerName());
        	List<GcCustomer> culis = gcCustomerService.selectGcCustomerList(gcCustomer);
        	
        	GcProjectQtfy l_gcProjectQtfy = new GcProjectQtfy();
        	l_gcProjectQtfy.setId(qtfylis.get(0).getId());
        	if(culis!=null && culis.size()>0){
        		l_gcProjectQtfy.setSupplyId(culis.get(0).getId());
        	}
        	l_gcProjectQtfy.setSupplyName(gcProject.getCustomerName());
        	l_gcProjectQtfy.setZongje(gcProject.getZongje());//保证金
        	gcProjectQtfyService.updateGcProjectYbfy(l_gcProjectQtfy);
    	}else{
    		addQtfk(gcProject);
    	}
    }
    
    /**
     * 新增项目Fapiao
     */
    /**
     * 修改项目Fapiao
     */
    @RequiresPermissions("gcgl:project:editFapiao")
    @GetMapping("/editFapiao/{id}")
    public String editFapiao(@PathVariable("id") Long id, ModelMap mmap){
        GcProject gcProject = gcProjectService.selectGcProjectById(id);
        mmap.put("gcProject", gcProject);
        return prefix + "/editFapiao";
    }

    /**
     * 新增保存项目Fapiao
     */
    @RequiresPermissions("gcgl:project:editFapiao")
    @Log(title = "项目开立发票", businessType = BusinessType.UPDATE)
    @PostMapping("/addFapiaoSave")
    @ResponseBody
    public AjaxResult addFapiaoSave(GcProject gcProject){
    	gcProject.setUpdateAt(new Date());
    	gcProject.setUpdateUser(getLoginName());
    	gcProjectService.updateGcProject(gcProject);
    	
    	GcProjectFlow gcProjectFlow = new GcProjectFlow();
    	gcProjectFlow.setGcProjectid(gcProject.getId());
    	gcProjectFlow.setSqkpsk(2);
    	gcProjectFlow.setXmss(2);
//    	gcProjectFlow.setXmjs(1);
    	gcProjectFlow.setUpdateAt(new Date());
    	gcProjectFlow.setUpdateUser(getLoginName());
    	gcProjectFlowService.updateGcProjectFlow(gcProjectFlow);
        return toAjax(1);
    }

    /**
     * 修改项目立项
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GcProject gcProject = gcProjectService.selectGcProjectById(id);
        mmap.put("gcProject", gcProject);
        GcCustomer gcCustomer = new GcCustomer();
    	gcCustomer.setDeleteFlag(1);
    	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
    	mmap.put("clis", gcCustomerlis);
    	
    	GcProjectGroup gcProjectGroup = new GcProjectGroup();
    	gcProjectGroup.setDeleteFlag(1);
    	List<GcProjectGroup> grouplis = gcProjectGroupService.selectGcProjectGroupList(gcProjectGroup);
    	mmap.put("glis", grouplis);
    	
        return prefix + "/edit";
    }
    
    /**
     * 项目评审
     */
    @RequiresPermissions("gcgl:project:psview")
    @GetMapping("/ps")
    public String projectps(){
        return prefix + "/projectps";
    }
    
    /**
     * 查询项目立项列表
     */
    @PostMapping("/listps")
    @ResponseBody
    public TableDataInfo listps(GcProject gcProject)
    {
        startPage();
        gcProject.setStatus(0);
        gcProject.setDeleteFlag(1);
        gcProject.setSpr(getLoginName());
        List<GcProject> list = gcProjectService.selectGcProjectList(gcProject);
        for(GcProject obj:list){
        	GcProjectFlow gcProjectFlow = new GcProjectFlow();
            gcProjectFlow.setDeleteFlag(1);
            gcProjectFlow.setGcProjectid(obj.getId());
            List<GcProjectFlow> flowlis = gcProjectFlowService.selectGcProjectFlowList(gcProjectFlow);
            GcProjectFlow l_flow = flowlis.get(0);
            if(l_flow.getCbyg()==1 && l_flow.getZjbj()==1 && l_flow.getQtwj()==1 
            		&& l_flow.getSjtz()==1 && l_flow.getHtxq()==1){
            	obj.setFlag("1");
            }else{
            	obj.setFlag("0");
            }
        }
        
        return getDataTable(list);
    }
    
    @Log(title = "项目立项通过", businessType = BusinessType.UPDATE)
    @PostMapping("/yes")
    @ResponseBody
    public AjaxResult yes(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProject gcProject = new GcProject();
        	gcProject.setId(Long.parseLong(id[i]));
        	gcProject.setStatus(1);
        	gcProject.setSpr(getLoginName());
        	gcProject.setSprAt(new Date());
        	gcProject.setSpyj(spyj);
        	gcProjectService.updateGcProject(gcProject);
        	
        	GcProject obj = gcProjectService.selectGcProjectById(Long.parseLong(id[i]));
        	//发送消息通知
//        	gcSendTipService.sendTipXm("xmht", obj.getName(), obj.getOrderNo(), 
//        			obj.getCreateUser(), DateUtils.dateTime(obj.getCreateAt()), 
//        			obj.getStatus().toString(), null, obj.getId().toString());
        	
        	try {
//        		List<Map> userlis = gcSendTipMapper.selectGcToUserByName(gcProject.getCreateUser());
//        		if(userlis!=null && userlis.size()>0){
//        			String phonenumber = userlis.get(0).get("phonenumber").toString();//创建人
        		String phonenumber = zjl;
        			AliyunSmsUtils.returnSmsTz(phonenumber);
//        		}
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}
    	}
    	
    	return toAjax(1);
    }
    
    @Log(title = "项目立项不通过", businessType = BusinessType.UPDATE)
    @PostMapping("/no")
    @ResponseBody
    public AjaxResult no(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProject gcProject = new GcProject();
        	gcProject.setId(Long.parseLong(id[i]));
        	gcProject.setStatus(2);
        	gcProject.setSpr(getLoginName());
        	gcProject.setSprAt(new Date());
        	gcProject.setSpyj(spyj);
        	gcProjectService.updateGcProject(gcProject);
        	
        	GcProject obj = gcProjectService.selectGcProjectById(Long.parseLong(id[i]));
        	//发送消息通知
//        	gcSendTipService.sendTipXm("xmht", obj.getName(), obj.getOrderNo(), 
//        			obj.getCreateUser(), DateUtils.dateTime(obj.getCreateAt()), 
//        			obj.getStatus().toString(), null, obj.getId().toString());
        	
        	try {
        		List<Map> userlis = gcSendTipMapper.selectGcToUserByName(gcProject.getCreateUser());
        		if(userlis!=null && userlis.size()>0){
        			String phonenumber = userlis.get(0).get("phonenumber").toString();//创建人
        			AliyunSmsUtils.returnSmsTz(phonenumber);
        		}
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}
    	}
    	return toAjax(1);
    }
    
    /**
     * 项目评审
     */
    @RequiresPermissions("gcgl:project:zjlpsview")
    @GetMapping("/zjlps")
    public String projectzjlps(){
        return prefix + "/projectzjlps";
    }
    
    /**
     * 查询项目立项列表
     */
    @PostMapping("/listzjlps")
    @ResponseBody
    public TableDataInfo listzjlps(GcProject gcProject)
    {
        startPage();
        gcProject.setStatus(1);
        gcProject.setDeleteFlag(1);
        List<GcProject> list = gcProjectService.selectGcProjectList(gcProject);
        for(GcProject obj:list){
        	GcProjectFlow gcProjectFlow = new GcProjectFlow();
            gcProjectFlow.setDeleteFlag(1);
            gcProjectFlow.setGcProjectid(obj.getId());
            List<GcProjectFlow> flowlis = gcProjectFlowService.selectGcProjectFlowList(gcProjectFlow);
            GcProjectFlow l_flow = flowlis.get(0);
            if(l_flow.getCbyg()==1 && l_flow.getZjbj()==1 && l_flow.getQtwj()==1 
            		&& l_flow.getSjtz()==1 && l_flow.getHtxq()==1){
            	obj.setFlag("1");
            }else{
            	obj.setFlag("0");
            }
        }
        
        return getDataTable(list);
    }
    
    @Log(title = "项目立项通过", businessType = BusinessType.UPDATE)
    @PostMapping("/zjlyes")
    @ResponseBody
    public AjaxResult zjlyes(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProject gcProject = new GcProject();
        	gcProject.setId(Long.parseLong(id[i]));
        	gcProject.setStatus(3);
        	gcProject.setZjlsh(getLoginName());
        	gcProject.setZjlshAt(new Date());
        	gcProject.setSpyj(spyj);
        	gcProjectService.updateGcProject(gcProject);
        	
        	GcProjectFlow gcProjectFlow = new GcProjectFlow();
        	gcProjectFlow.setGcProjectid(Long.parseLong(id[i]));
        	gcProjectFlow.setSjtz(2);
        	gcProjectFlow.setQtwj(2); 
            gcProjectFlow.setZjbj(2);
            gcProjectFlow.setCbyg(2);
            gcProjectFlow.setHtxq(2);
//            gcProjectFlow.setXmqtfy(2);//项目其它费用
        	gcProjectFlow.setXmps(2);
        	gcProjectFlow.setXmss(1);
        	gcProjectFlow.setXmht(1);
        	gcProjectFlow.setSqkpsk(1);
        	gcProjectFlow.setSbclht(1);
        	gcProjectFlow.setShazht(1);
        	gcProjectFlow.setGcqtht(1);
        	gcProjectFlow.setYbxfy(1);
        	gcProjectFlow.setXmjs(0);
        	gcProjectFlow.setShazhtjgcl(0);//项目竣工资料
        	gcProjectFlow.setSqkpsksk(1);
        	gcProjectFlow.setUpdateAt(new Date());
        	gcProjectFlow.setUpdateUser(getLoginName());
        	gcProjectFlowService.updateGcProjectFlow(gcProjectFlow);
        	
        	GcProject obj = gcProjectService.selectGcProjectById(Long.parseLong(id[i]));
        	//发送消息通知
//        	gcSendTipService.sendTipXm("xmht", obj.getName(), obj.getOrderNo(), 
//        			obj.getCreateUser(), DateUtils.dateTime(obj.getCreateAt()), 
//        			obj.getStatus().toString(), null, obj.getId().toString());
        	
        	try {
        		List<Map> userlis = gcSendTipMapper.selectGcToUserByName(gcProject.getCreateUser());
        		if(userlis!=null && userlis.size()>0){
        			String phonenumber = userlis.get(0).get("phonenumber").toString();//创建人
        			AliyunSmsUtils.returnSmsTz(phonenumber);
        		}
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}
    	}
    	
    	return toAjax(1);
    }
    
    @Log(title = "项目立项不通过", businessType = BusinessType.UPDATE)
    @PostMapping("/zjlno")
    @ResponseBody
    public AjaxResult zjlno(String ids,String spyj, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProject gcProject = new GcProject();
        	gcProject.setId(Long.parseLong(id[i]));
        	gcProject.setStatus(4);
        	gcProject.setZjlsh(getLoginName());
        	gcProject.setZjlshAt(new Date());
        	gcProject.setSpyj(spyj);
        	gcProjectService.updateGcProject(gcProject);
        	
        	GcProjectFlow gcProjectFlow = new GcProjectFlow();
        	gcProjectFlow.setGcProjectid(Long.parseLong(id[i]));
        	gcProjectFlow.setXmps(0);
        	gcProjectFlow.setXmss(0);
        	gcProjectFlow.setSqkpsk(0);
        	gcProjectFlow.setSbclht(0);
        	gcProjectFlow.setShazht(0);
        	gcProjectFlow.setGcqtht(0);
        	gcProjectFlow.setYbxfy(0);
        	gcProjectFlow.setXmjs(0);
        	gcProjectFlow.setSqkpsksk(0);
        	gcProjectFlow.setUpdateAt(new Date());
        	gcProjectFlow.setUpdateUser(getLoginName());
        	gcProjectFlowService.updateGcProjectFlow(gcProjectFlow);
        	
        	GcProject obj = gcProjectService.selectGcProjectById(Long.parseLong(id[i]));
        	//发送消息通知
//        	gcSendTipService.sendTipXm("xmht", obj.getName(), obj.getOrderNo(), 
//        			obj.getCreateUser(), DateUtils.dateTime(obj.getCreateAt()), 
//        			obj.getStatus().toString(), null, obj.getId().toString());
        	
        	try {
        		List<Map> userlis = gcSendTipMapper.selectGcToUserByName(gcProject.getCreateUser());
        		if(userlis!=null && userlis.size()>0){
        			String phonenumber = userlis.get(0).get("phonenumber").toString();//创建人
        			AliyunSmsUtils.returnSmsTz(phonenumber);
        		}
    		} catch (Exception e) {
    			// TODO: handle exception
    			e.printStackTrace();
    		}
    	}
    	return toAjax(1);
    }

    /**
     * 修改保存项目立项
     */
    @Log(title = "项目立项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GcProject gcProject){
    	
    	gcProjectService.updateGcProject(gcProject);
    	
    	if(gcProject.getZongje()!=null && !gcProject.getZongje().equals("")){
    		updateQtfk(gcProject);
    	}
    	
    	try {
    		//成本评估
        	GcProjectCbpj gcProjectCbpj = new GcProjectCbpj();
        	gcProjectCbpj.setGcProjectid(gcProject.getId());
        	gcProjectCbpj.setOrderNo(gcProject.getOrderNo());
        	gcProjectCbpjService.updateGcProjectCbpj4Gid(gcProjectCbpj);
        	//其他文件
        	GcProjectQtwj gcProjectQtwj = new GcProjectQtwj();
        	gcProjectQtwj.setGcProjectid(gcProject.getId());
        	gcProjectQtwj.setOrderNo(gcProject.getOrderNo());
        	gcProjectQtwjService.updateGcProjectQtwj4Gid(gcProjectQtwj);
        	//设计图纸
        	GcProjectSjtz gcProjectSjtz = new GcProjectSjtz();
        	gcProjectSjtz.setGcProjectid(gcProject.getId());
        	gcProjectSjtz.setOrderNo(gcProject.getOrderNo());
        	gcProjectSjtzService.updateGcProjectSjtz4Gid(gcProjectSjtz);
        	//造价
        	GcProjectZjbj gcProjectZjbj = new GcProjectZjbj();
        	gcProjectZjbj.setGcProjectid(gcProject.getId());
        	gcProjectZjbj.setOrderNo(gcProject.getOrderNo());
        	gcProjectZjbjService.updateGcProjectZjbj4Gid(gcProjectZjbj);
        	//项目详情
        	GcProjectXmxq gcProjectXmxq = new GcProjectXmxq();
        	gcProjectXmxq.setGcProjectid(gcProject.getId());
        	gcProjectXmxq.setOrderNo(gcProject.getOrderNo());
        	gcProjectXmxqService.updateGcProjectXmxq4Gid(gcProjectXmxq);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
    	
        return toAjax(1);
    }

    /**
     * 删除项目立项
     */
    @RequiresPermissions("gcgl:project:remove")
    @Log(title = "项目立项", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gcProjectService.deleteGcProjectByIds(ids));
    }
    
    //项目结算发票
    @RequiresPermissions("gcgl:project:jxfpview")
    @GetMapping("/projectJxfp")
    public String projectJxfp(){
        return prefix + "/projectJxfp";
    }
    
    /**
     * 查询项目立项列表
     */
    @PostMapping("/listJxfp")
    @ResponseBody
    public TableDataInfo listJxfp(GcProject gcProject)
    {
        startPage();
        gcProject.setDeleteFlag(1);
        if(getSysUser().isShow43R(getUserId())){
        	gcProject.setCreateUser(getLoginName());
        }
        List<GcProject> list = gcProjectService.selectGcProjectList(gcProject);
        return getDataTable(list);
    }
    
    //项目结算发票时间
    @RequiresPermissions("gcgl:project:jxfp4Atview")
    @GetMapping("/projectJxfp4At")
    public String projectJxfp4At(){
        return prefix + "/projectJxfp4At";
    }
    
    /**
     * 查询项目立项列表
     */
    @PostMapping("/listJxfp4At")
    @ResponseBody
    public TableDataInfo listJxfp4At(GcProject gcProject){
        startPage();
        gcProject.setDeleteFlag(1);
        List<GcProject> list = gcProjectService.selectGcProject4AtList(gcProject);
        return getDataTable(list);
    }
    
    @GetMapping("/print4At/{jsNo}")
    public String print4At(@PathVariable("jsNo") String jsNo, ModelMap mmap){
    	
    	GcProject gcProject = new GcProject();
    	gcProject.setDeleteFlag(1);
    	gcProject.setJsNo(jsNo);
    	List<GcProject> gcProjectlis = gcProjectService.selectGcProjectList(gcProject);
    	
    	List<Map> replis = new ArrayList<Map>();
    	double heje = 0.0;
    	double dkseje = 0.0;
    	for(GcProject obj:gcProjectlis){
        	//1设备材料合同\2施工安装合同\3工程其它合同\4一般性费用\5项目其它费用
        	GcFkfp gcFkfp = new GcFkfp();
        	gcFkfp.setDeleteFlag(1);
        	gcFkfp.setGcProjectid(obj.getId());
        	List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
        	for(GcFkfp fp:fplis){
        		
        		GcSupply gcSupply = new GcSupply();
        		gcSupply.setDeleteFlag(1);
        		gcSupply.setName(fp.getCkdw());
        		List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
        		
        		Map rep = new HashMap();
    			rep.put("jbr", fp.getCreateUser());//经办人
    			rep.put("cblx", fp.getXmtype());//成本类型
    			rep.put("fpdyxm", fp.getXmmc());//发票对应项目
    			rep.put("kpdwmc", fp.getCkdw());//开票单位名称
    			rep.put("xfsh", (supplylis!=null && supplylis.size()>0)?supplylis.get(0).getNssbh():"");//销方税号
    			rep.put("type", fp.getFpType());//类型
    			rep.put("kpsj", fp.getFpriq());//开票时间
    			rep.put("fphm", fp.getFpNo());//发票号码
    			rep.put("shul", 1);//数量
    			rep.put("suil", fp.getFpsl()+"%");//税率
    			rep.put("jine", fp.getFpjine());//金额

    			//公式：金额/(1+13%)*13%
    			double dkse = DecimalCalculateUtil.mul(DecimalCalculateUtil.div(Double.valueOf(fp.getFpjine().toString()), 
    					Double.valueOf(1+(Double.parseDouble(fp.getFpsl())/100)),2),(DecimalCalculateUtil.div(Double.parseDouble(fp.getFpsl()),100,2)));
    			
    			rep.put("dkse", dkse);//抵扣税额
    			rep.put("hej", fp.getFpjine());//合计
    			heje+=Double.parseDouble(fp.getFpjine().toString());
    			dkseje+=dkse;
    			replis.add(rep);
        	}
    	}
    	
    	mmap.put("jsNo", jsNo);
    	mmap.put("replis", replis);
    	mmap.put("gsmc", gsmc);
    	mmap.put("sbh", sbh);
    	mmap.put("riq", new Date());
    	mmap.put("heje", heje);
    	mmap.put("hejedx", ConvertUpMoneyUtil.toChinese(String.valueOf(heje)));
    	mmap.put("kj", "");
    	mmap.put("zjl", "");
    	mmap.put("head", DateUtils.dateTimeNow(DateUtils.YYYY)+"年"+DateUtils.dateTimeNow(DateUtils.MM)+"月");
    	mmap.put("dkseje", dkseje);
    	return prefix + "/projectprintAt";
    }
    
    @GetMapping("/print/{projectId}")
    public String print(@PathVariable("projectId") Long projectId, ModelMap mmap){
    	List<Map> replis = new ArrayList<Map>();
    	
    	double heje = 0.0;
    	double dkseje = 0.0;
    	//1设备材料合同\2施工安装合同\3工程其它合同\4一般性费用\5项目其它费用
    	GcFkfp gcFkfp = new GcFkfp();
    	gcFkfp.setDeleteFlag(1);
    	gcFkfp.setGcProjectid(projectId);
    	List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
    	for(GcFkfp fp:fplis){
    		
    		GcSupply gcSupply = new GcSupply();
    		gcSupply.setDeleteFlag(1);
    		gcSupply.setName(fp.getCkdw());
    		List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
    		
    		Map rep = new HashMap();
			rep.put("jbr", fp.getCreateUser());//经办人
			rep.put("cblx", fp.getXmtype());//成本类型
			rep.put("fpdyxm", fp.getXmmc());//发票对应项目
			rep.put("kpdwmc", fp.getCkdw());//开票单位名称
			rep.put("xfsh", (supplylis!=null && supplylis.size()>0)?supplylis.get(0).getNssbh():"");//销方税号
			rep.put("type", fp.getFpType());//类型
			rep.put("kpsj", fp.getFpriq());//开票时间
			rep.put("fphm", fp.getFpNo());//发票号码
			rep.put("shul", 1);//数量
			rep.put("suil", fp.getFpsl()+"%");//税率
			rep.put("jine", fp.getFpjine());//金额

			//公式：金额/(1+13%)*13%
			double dkse = DecimalCalculateUtil.mul(DecimalCalculateUtil.div(Double.valueOf(fp.getFpjine().toString()), 
					Double.valueOf(1+(Double.parseDouble(fp.getFpsl())/100)),2),(DecimalCalculateUtil.div(Double.parseDouble(fp.getFpsl()),100,2)));
			
			rep.put("dkse", dkse);//抵扣税额
			rep.put("hej", fp.getFpjine());//合计
			heje+=Double.parseDouble(fp.getFpjine().toString());
			dkseje+=dkse;
			replis.add(rep);
    	}
    	
    	mmap.put("projectId", projectId);
    	mmap.put("replis", replis);
    	mmap.put("gsmc", gsmc);
    	mmap.put("sbh", sbh);
    	mmap.put("riq", new Date());
    	mmap.put("heje", heje);
    	mmap.put("hejedx", ConvertUpMoneyUtil.toChinese(String.valueOf(heje)));
    	mmap.put("kj", "");
    	mmap.put("zjl", "");
    	mmap.put("head", DateUtils.dateTimeNow(DateUtils.YYYY)+"年"+DateUtils.dateTimeNow(DateUtils.MM)+"月");
    	mmap.put("dkseje", dkseje);
    	return prefix + "/projectprint";
    }
    
    /**
     * 项目立项详情
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap){
        GcProject gcProject = gcProjectService.selectGcProjectById(id);
        mmap.put("gcProject", gcProject);
    	
    	//成本评估
    	GcProjectCbpj gcProjectCbpjobj = new GcProjectCbpj();
    	gcProjectCbpjobj.setDeleteFlag(1);
    	gcProjectCbpjobj.setGcProjectid(id);
    	List<GcProjectCbpj> cbpjlis = gcProjectCbpjService.selectGcProjectCbpjList(gcProjectCbpjobj);
    	for(GcProjectCbpj obj:cbpjlis){
        	if(obj.getSpyj()!=null && !obj.getSpyj().equals("")){
            	String[] zlis = obj.getSpyj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setSpyj(file);
            }
        }
    	if(cbpjlis!=null && cbpjlis.size()>0){
    		gcProjectCbpjobj = cbpjlis.get(0);
    		List<GcProjectCbpjitem> itemlis= gcProjectCbpjitemService.selectGcProjectCbpjitemByCbpjId(gcProjectCbpjobj.getId());
    		gcProjectCbpjobj.setItem(itemlis);
    	}
        mmap.put("cbpjObj", gcProjectCbpjobj);
        mmap.put("cbpjwjlis", (cbpjlis==null || cbpjlis.size()==0)?null:cbpjlis.get(0).getSpyj());
        
        //其他文件
        GcProjectQtwj gcProjectQtwj = new GcProjectQtwj();
        gcProjectQtwj.setDeleteFlag(1);
        gcProjectQtwj.setGcProjectid(id);
        List<GcProjectQtwj> qtwjlis = gcProjectQtwjService.selectGcProjectQtwjList(gcProjectQtwj);
        for(GcProjectQtwj obj:qtwjlis){
        	if(obj.getZilwj()!=null && !obj.getZilwj().equals("")){
            	String[] zlis = obj.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZilwj(file);
            }
        }
        mmap.put("qtwjlis", (qtwjlis==null || qtwjlis.size()==0)?null:qtwjlis.get(0).getZilwj());
        
        //设计图纸
        GcProjectSjtz gcProjectSjtz = new GcProjectSjtz();
        gcProjectSjtz.setDeleteFlag(1);
        gcProjectSjtz.setGcProjectid(id);
        List<GcProjectSjtz> sjtzlis = gcProjectSjtzService.selectGcProjectSjtzList(gcProjectSjtz);
        for(GcProjectSjtz sjtz:sjtzlis){
        	if(sjtz.getZilwj()!=null && !sjtz.getZilwj().equals("")){
            	String[] zlis = sjtz.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	sjtz.setZilwj(file);
            }
        }
        mmap.put("sjtzlis", (sjtzlis==null || sjtzlis.size()==0)?null:sjtzlis.get(0).getZilwj());
        
        //造价报价
        GcProjectZjbj gcProjectZjbj = new GcProjectZjbj();
        gcProjectZjbj.setDeleteFlag(1);
        gcProjectZjbj.setGcProjectid(id);
        List<GcProjectZjbj> zjbjlis = gcProjectZjbjService.selectGcProjectZjbjList(gcProjectZjbj);
        for(GcProjectZjbj obj:zjbjlis){
        	if(obj.getZilwj()!=null && !obj.getZilwj().equals("")){
            	String[] zlis = obj.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZilwj(file);
            }
        }
        mmap.put("zjbjlis", (zjbjlis==null || zjbjlis.size()==0)?null:zjbjlis.get(0).getZilwj());
        
        //项目详情
        GcProjectXmxq gcProjectXmxq = new GcProjectXmxq();
        gcProjectXmxq.setDeleteFlag(1);
        gcProjectXmxq.setGcProjectid(id);
        List<GcProjectXmxq> xmxqlis = gcProjectXmxqService.selectGcProjectXmxqList(gcProjectXmxq);
        for(GcProjectXmxq obj:xmxqlis){
        	if(obj.getZilwj()!=null && !obj.getZilwj().equals("")){
            	String[] zlis = obj.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZilwj(file);
            }
        	
        	if(obj.getZhengsht()!=null && !obj.getZhengsht().equals("")){
            	String[] zlis = obj.getZhengsht().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZhengsht(file);
            }
        }
        mmap.put("xmxq", (xmxqlis==null || xmxqlis.size()==0)?new GcProjectXmxq():xmxqlis.get(0));
        
        //项目保证金/服务费等
        GcProjectQtfy gcProjectQtfy = new GcProjectQtfy();
        gcProjectQtfy.setDeleteFlag(1);
        gcProjectQtfy.setGcProjectid(id);
        List<GcProjectQtfy> qtfylis = gcProjectQtfyService.selectGcProjectYbfyList(gcProjectQtfy);
        for(GcProjectQtfy obj:qtfylis){
        	if(obj.getZlwj()!=null && !obj.getZlwj().equals("")){
            	String[] zlis = obj.getZlwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZlwj(file);
            }
        }
        mmap.put("qtfylis", (qtfylis==null || qtfylis.size()==0)?new GcProjectQtfy():qtfylis.get(0));
        
        return prefix + "/detail";
    }
    
//    @RequiresPermissions("gcgl:project:projectYsview")
    @GetMapping("/projectYs")
    public String projectYs(){
        return prefix + "/projectYs";
    }

    /**
     * 查询项目立项列表
     */
    @PostMapping("/listYs")
    @ResponseBody
    public TableDataInfo listYs(GcProject gcProject){
        startPage();
        gcProject.setDeleteFlag(1);
        List<GcProject> list = gcProjectService.selectGcProjectList(gcProject);
        return getDataTable(list);
    }
    
//    @RequiresPermissions("gcgl:project:finish")
    @Log(title = "项目竣工验收", businessType = BusinessType.UPDATE)
    @PostMapping("/finish")
    @ResponseBody
    public AjaxResult finish(String ids, ModelMap mmap){
    	String[] id = Convert.toStrArray(ids);
    	for(int i=0;i<id.length;i++){
    		GcProject gcProject = new GcProject();
        	gcProject.setId(Long.parseLong(id[i]));
        	gcProject.setStatus(5);
        	gcProject.setUpdateUser(getLoginName());
        	gcProject.setUpdateAt(new Date());
        	gcProjectService.updateGcProject(gcProject);
        	
        	GcProjectFlow gcProjectFlow = new GcProjectFlow();
        	gcProjectFlow.setGcProjectid(Long.parseLong(id[i]));
        	gcProjectFlow.setSbclht(2);
        	gcProjectFlow.setSbclhtcrk(2);
        	gcProjectFlow.setSbclhtfk(2);
        	gcProjectFlow.setSbclhtfp(2);
        	gcProjectFlow.setSbclhtjhd(2);
        	gcProjectFlow.setSbclhtps(2);
        	gcProjectFlow.setShazht(2);
        	gcProjectFlow.setShazhtfk(2);
        	gcProjectFlow.setShazhtfp(2);
        	gcProjectFlow.setShazhtgc(2);
        	gcProjectFlow.setShazhtjgcl(2);
        	gcProjectFlow.setShazhtjgys(2);
        	gcProjectFlow.setShazhtps(2);
        	gcProjectFlow.setGcqtht(2);
        	gcProjectFlow.setGcqthtfk(2);
        	gcProjectFlow.setGcqthtfp(2);
        	gcProjectFlow.setGcqthtps(2);
        	gcProjectFlow.setYbxfy(2);
        	gcProjectFlow.setYbxfyfk(2);
        	gcProjectFlow.setYbxfyfp(2);
        	gcProjectFlow.setXmjs(2);
        	gcProjectFlow.setSqkpsk(2);
        	gcProjectFlow.setSqkpsksk(2);
        	gcProjectFlow.setSqkpsksp(2);
        	gcProjectFlow.setXmss(2);
        	gcProjectFlow.setXmht(2);
        	gcProjectFlowService.updateGcProjectFlow(gcProjectFlow);
    	}
    	
    	return toAjax(1);
    }
    
    /**
     * 项目立项详情
     */
    @GetMapping("/detailgcsp/{id}")
    public String detailgcsp(@PathVariable("id") Long id, ModelMap mmap){
    	GcProject gcProject = gcProjectService.selectGcProjectById(id);
        mmap.put("gcProject", gcProject);
    	
        //成本评估
    	GcProjectCbpj gcProjectCbpjobj = new GcProjectCbpj();
    	gcProjectCbpjobj.setDeleteFlag(1);
    	gcProjectCbpjobj.setGcProjectid(id);
    	List<GcProjectCbpj> cbpjlis = gcProjectCbpjService.selectGcProjectCbpjList(gcProjectCbpjobj);
    	for(GcProjectCbpj obj:cbpjlis){
        	if(obj.getSpyj()!=null && !obj.getSpyj().equals("")){
            	String[] zlis = obj.getSpyj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setSpyj(file);
            }
        }
    	if(cbpjlis!=null && cbpjlis.size()>0){
    		gcProjectCbpjobj = cbpjlis.get(0);
    		List<GcProjectCbpjitem> itemlis= gcProjectCbpjitemService.selectGcProjectCbpjitemByCbpjId(gcProjectCbpjobj.getId());
    		gcProjectCbpjobj.setItem(itemlis);
    	}
        mmap.put("cbpjObj", gcProjectCbpjobj);
        mmap.put("cbpjwjlis", (cbpjlis==null || cbpjlis.size()==0)?null:cbpjlis.get(0).getSpyj());
        
        
        //其他文件
        GcProjectQtwj gcProjectQtwj = new GcProjectQtwj();
        gcProjectQtwj.setDeleteFlag(1);
        gcProjectQtwj.setGcProjectid(id);
        List<GcProjectQtwj> qtwjlis = gcProjectQtwjService.selectGcProjectQtwjList(gcProjectQtwj);
        for(GcProjectQtwj obj:qtwjlis){
        	if(obj.getZilwj()!=null && !obj.getZilwj().equals("")){
            	String[] zlis = obj.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZilwj(file);
            }
        }
        mmap.put("qtwjlis", (qtwjlis==null || qtwjlis.size()==0)?new GcProjectQtwj():qtwjlis.get(0).getZilwj());
        
        //设计图纸
        GcProjectSjtz gcProjectSjtz = new GcProjectSjtz();
        gcProjectSjtz.setDeleteFlag(1);
        gcProjectSjtz.setGcProjectid(id);
        List<GcProjectSjtz> sjtzlis = gcProjectSjtzService.selectGcProjectSjtzList(gcProjectSjtz);
        for(GcProjectSjtz sjtz:sjtzlis){
        	if(sjtz.getZilwj()!=null && !sjtz.getZilwj().equals("")){
            	String[] zlis = sjtz.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	sjtz.setZilwj(file);
            }
        }
        mmap.put("sjtzlis", (sjtzlis==null || sjtzlis.size()==0)?new GcProjectSjtz():sjtzlis.get(0).getZilwj());
        
        //造价报价
        GcProjectZjbj gcProjectZjbj = new GcProjectZjbj();
        gcProjectZjbj.setDeleteFlag(1);
        gcProjectZjbj.setGcProjectid(id);
        List<GcProjectZjbj> zjbjlis = gcProjectZjbjService.selectGcProjectZjbjList(gcProjectZjbj);
        for(GcProjectZjbj obj:zjbjlis){
        	if(obj.getZilwj()!=null && !obj.getZilwj().equals("")){
            	String[] zlis = obj.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZilwj(file);
            }
        }
        mmap.put("zjbjlis", (zjbjlis==null || zjbjlis.size()==0)?new GcProjectZjbj():zjbjlis.get(0).getZilwj());
        
        //项目详情
        GcProjectXmxq gcProjectXmxq = new GcProjectXmxq();
        gcProjectXmxq.setDeleteFlag(1);
        gcProjectXmxq.setGcProjectid(id);
        List<GcProjectXmxq> xmxqlis = gcProjectXmxqService.selectGcProjectXmxqList(gcProjectXmxq);
        for(GcProjectXmxq obj:xmxqlis){
        	if(obj.getZilwj()!=null && !obj.getZilwj().equals("")){
            	String[] zlis = obj.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZilwj(file);
            }
        }
        mmap.put("xmxq", (xmxqlis==null || xmxqlis.size()==0)?new GcProjectXmxq():xmxqlis.get(0));
        
        //项目保证金/服务费等
        GcProjectQtfy gcProjectQtfy = new GcProjectQtfy();
        gcProjectQtfy.setDeleteFlag(1);
        gcProjectQtfy.setGcProjectid(id);
        List<GcProjectQtfy> qtfylis = gcProjectQtfyService.selectGcProjectYbfyList(gcProjectQtfy);
        for(GcProjectQtfy obj:qtfylis){
        	if(obj.getZlwj()!=null && !obj.getZlwj().equals("")){
            	String[] zlis = obj.getZlwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZlwj(file);
            }
        }
        mmap.put("qtfylis", (qtfylis==null || qtfylis.size()==0)?new GcProjectQtfy():qtfylis.get(0));
        
        return prefix + "/detailgcsp";
    }
    
    /**
     * 项目立项详情
     */
    @GetMapping("/detailzjlsp/{id}")
    public String detailzjlsp(@PathVariable("id") Long id, ModelMap mmap){
    	GcProject gcProject = gcProjectService.selectGcProjectById(id);
        mmap.put("gcProject", gcProject);
    	
        //成本评估
    	GcProjectCbpj gcProjectCbpjobj = new GcProjectCbpj();
    	gcProjectCbpjobj.setDeleteFlag(1);
    	gcProjectCbpjobj.setGcProjectid(id);
    	List<GcProjectCbpj> cbpjlis = gcProjectCbpjService.selectGcProjectCbpjList(gcProjectCbpjobj);
    	for(GcProjectCbpj obj:cbpjlis){
        	if(obj.getSpyj()!=null && !obj.getSpyj().equals("")){
            	String[] zlis = obj.getSpyj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setSpyj(file);
            }
        }
    	if(cbpjlis!=null && cbpjlis.size()>0){
    		gcProjectCbpjobj = cbpjlis.get(0);
    		List<GcProjectCbpjitem> itemlis= gcProjectCbpjitemService.selectGcProjectCbpjitemByCbpjId(gcProjectCbpjobj.getId());
    		gcProjectCbpjobj.setItem(itemlis);
    	}
        mmap.put("cbpjObj", gcProjectCbpjobj);
        mmap.put("cbpjwjlis", (cbpjlis==null || cbpjlis.size()==0)?null:cbpjlis.get(0).getSpyj());
        
        
        //其他文件
        GcProjectQtwj gcProjectQtwj = new GcProjectQtwj();
        gcProjectQtwj.setDeleteFlag(1);
        gcProjectQtwj.setGcProjectid(id);
        List<GcProjectQtwj> qtwjlis = gcProjectQtwjService.selectGcProjectQtwjList(gcProjectQtwj);
        for(GcProjectQtwj obj:qtwjlis){
        	if(obj.getZilwj()!=null && !obj.getZilwj().equals("")){
            	String[] zlis = obj.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZilwj(file);
            }
        }
        mmap.put("qtwjlis", (qtwjlis==null || qtwjlis.size()==0)?new GcProjectQtwj():qtwjlis.get(0).getZilwj());
        
        //设计图纸
        GcProjectSjtz gcProjectSjtz = new GcProjectSjtz();
        gcProjectSjtz.setDeleteFlag(1);
        gcProjectSjtz.setGcProjectid(id);
        List<GcProjectSjtz> sjtzlis = gcProjectSjtzService.selectGcProjectSjtzList(gcProjectSjtz);
        for(GcProjectSjtz sjtz:sjtzlis){
        	if(sjtz.getZilwj()!=null && !sjtz.getZilwj().equals("")){
            	String[] zlis = sjtz.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	sjtz.setZilwj(file);
            }
        }
        mmap.put("sjtzlis", (sjtzlis==null || sjtzlis.size()==0)?new GcProjectSjtz():sjtzlis.get(0).getZilwj());
        
        //造价报价
        GcProjectZjbj gcProjectZjbj = new GcProjectZjbj();
        gcProjectZjbj.setDeleteFlag(1);
        gcProjectZjbj.setGcProjectid(id);
        List<GcProjectZjbj> zjbjlis = gcProjectZjbjService.selectGcProjectZjbjList(gcProjectZjbj);
        for(GcProjectZjbj obj:zjbjlis){
        	if(obj.getZilwj()!=null && !obj.getZilwj().equals("")){
            	String[] zlis = obj.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZilwj(file);
            }
        }
        mmap.put("zjbjlis", (zjbjlis==null || zjbjlis.size()==0)?new GcProjectZjbj():zjbjlis.get(0).getZilwj());
        
        //项目详情
        GcProjectXmxq gcProjectXmxq = new GcProjectXmxq();
        gcProjectXmxq.setDeleteFlag(1);
        gcProjectXmxq.setGcProjectid(id);
        List<GcProjectXmxq> xmxqlis = gcProjectXmxqService.selectGcProjectXmxqList(gcProjectXmxq);
        for(GcProjectXmxq obj:xmxqlis){
        	if(obj.getZilwj()!=null && !obj.getZilwj().equals("")){
            	String[] zlis = obj.getZilwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZilwj(file);
            }
        }
        mmap.put("xmxq", (xmxqlis==null || xmxqlis.size()==0)?new GcProjectXmxq():xmxqlis.get(0));
        
        //项目保证金/服务费等
        GcProjectQtfy gcProjectQtfy = new GcProjectQtfy();
        gcProjectQtfy.setDeleteFlag(1);
        gcProjectQtfy.setGcProjectid(id);
        List<GcProjectQtfy> qtfylis = gcProjectQtfyService.selectGcProjectYbfyList(gcProjectQtfy);
        for(GcProjectQtfy obj:qtfylis){
        	if(obj.getZlwj()!=null && !obj.getZlwj().equals("")){
            	String[] zlis = obj.getZlwj().split(",");
            	String file = "";
            	for(int i=0;i<zlis.length;i++){
            		file += RuoYiConfig.getOnPath()+zlis[i]+",";
            	}
            	obj.setZlwj(file);
            }
        }
        mmap.put("qtfylis", (qtfylis==null || qtfylis.size()==0)?new GcProjectQtfy():qtfylis.get(0));
        
        return prefix + "/detailzjlsp";
    }
    
    /**
     * 
     * @param projectId
     * @return
     */
    @PostMapping("/exportJxfp")
    @ResponseBody
    public AjaxResult exportJxfp(int projectId){
    	List<GcProjectExeVo> replis = new ArrayList<GcProjectExeVo>();
    	
    	double heje = 0.0;
    	
    	GcFkfp gcFkfp = new GcFkfp();
    	gcFkfp.setDeleteFlag(1);
    	gcFkfp.setGcProjectid(Long.valueOf(projectId));
    	List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
    	for(GcFkfp fp:fplis){
    		GcSupply gcSupply = new GcSupply();
    		gcSupply.setDeleteFlag(1);
    		gcSupply.setName(fp.getCkdw());
    		List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
    		
    		GcProjectExeVo rep = new GcProjectExeVo();
			rep.setJbr(fp.getCreateUser());//经办人
			//1设备材料合同\2施工安装合同\3工程其它合同\4一般性费用\5项目其它费用
			if(fp.getXmtype()==1){
				rep.setCblx("设备材料合同");
			}else if(fp.getXmtype()==2){
				rep.setCblx("施工安装合同");
			}else if(fp.getXmtype()==3){
				rep.setCblx("工程其它合同");
			}else if(fp.getXmtype()==4){
				rep.setCblx("一般性费用");
			}else if(fp.getXmtype()==5){
				rep.setCblx("项目(保证金/服务费)");
			}
			rep.setFpdyxm(fp.getXmmc());//发票对应项目
			rep.setKpdwmc(fp.getCkdw());//开票单位名称
			rep.setXfsh((supplylis!=null && supplylis.size()>0)?supplylis.get(0).getNssbh():"");//销方税号
			rep.setType(fp.getFpType());//类型
			rep.setKpsj(DateUtils.dateTime(fp.getCreateAt()));//开票时间
			rep.setFphm(fp.getFpNo());//发票号码
			rep.setShul("1");//数量
			rep.setSuil(fp.getFpsl()+"%");//税率
			rep.setJine(fp.getFpjine().toString());//金额

			//公式：金额/(1+13%)*13%
			double dkse = DecimalCalculateUtil.mul(DecimalCalculateUtil.div(Double.valueOf(fp.getFpjine().toString()), 
					Double.valueOf(1+(Double.parseDouble(fp.getFpsl())/100)),2),(DecimalCalculateUtil.div(Double.parseDouble(fp.getFpsl()),100,2)));
			
			rep.setDkse(String.valueOf(dkse));//抵扣税额
			rep.setHej(String.valueOf(fp.getFpjine()));//合计
			heje+=Double.parseDouble(fp.getFpjine().toString());
			replis.add(rep);
    	}
    	
//    	mmap.put("replis", replis);
//    	mmap.put("gsmc", gsmc);
//    	mmap.put("sbh", sbh);
//    	mmap.put("riq", new Date());
//    	mmap.put("heje", heje);
//    	mmap.put("hejedx", ConvertUpMoneyUtil.toChinese(String.valueOf(heje)));
//    	mmap.put("kj", "");
//    	mmap.put("zjl", "");
//    	mmap.put("head", DateUtils.dateTimeNow(DateUtils.YYYY)+"年"+DateUtils.dateTimeNow(DateUtils.MM)+"月");
    	
        ExcelUtil<GcProjectExeVo> util = new ExcelUtil<GcProjectExeVo>(GcProjectExeVo.class);
        return util.exportExcel(replis, "项目结算数据");
    }
    
    @PostMapping("/exportJxfpAt")
    @ResponseBody
    public AjaxResult exportJxfpAt(String jsNo){
    	List<GcProjectExeVo> replis = new ArrayList<GcProjectExeVo>();
    	
    	double heje = 0.0;
    	GcProject gcProject = new GcProject();
    	gcProject.setDeleteFlag(1);
    	gcProject.setJsNo(jsNo);
    	List<GcProject> gcProjectlis = gcProjectService.selectGcProjectList(gcProject);
    	
    	for(GcProject gcProjectObj:gcProjectlis){
    		GcFkfp gcFkfp = new GcFkfp();
        	gcFkfp.setDeleteFlag(1);
        	gcFkfp.setGcProjectid(gcProjectObj.getId());
        	List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
        	for(GcFkfp fp:fplis){
        		GcSupply gcSupply = new GcSupply();
        		gcSupply.setDeleteFlag(1);
        		gcSupply.setName(fp.getCkdw());
        		List<GcSupply> supplylis = gcSupplyService.selectGcSupplyList(gcSupply);
        		
        		GcProjectExeVo rep = new GcProjectExeVo();
    			rep.setJbr(fp.getCreateUser());//经办人
    			//1设备材料合同\2施工安装合同\3工程其它合同\4一般性费用\5项目其它费用
    			if(fp.getXmtype()==1){
    				rep.setCblx("设备材料合同");
    			}else if(fp.getXmtype()==2){
    				rep.setCblx("施工安装合同");
    			}else if(fp.getXmtype()==3){
    				rep.setCblx("工程其它合同");
    			}else if(fp.getXmtype()==4){
    				rep.setCblx("一般性费用");
    			}else if(fp.getXmtype()==5){
    				rep.setCblx("项目(保证金/服务费)");
    			}
    			rep.setFpdyxm(fp.getXmmc());//发票对应项目
    			rep.setKpdwmc(fp.getCkdw());//开票单位名称
    			rep.setXfsh((supplylis!=null && supplylis.size()>0)?supplylis.get(0).getNssbh():"");//销方税号
    			rep.setType(fp.getFpType());//类型
    			rep.setKpsj(DateUtils.dateTime(fp.getCreateAt()));//开票时间
    			rep.setFphm(fp.getFpNo());//发票号码
    			rep.setShul("1");//数量
    			rep.setSuil(fp.getFpsl()+"%");//税率
    			rep.setJine(fp.getFpjine().toString());//金额

    			//公式：金额/(1+13%)*13%
    			double dkse = DecimalCalculateUtil.mul(DecimalCalculateUtil.div(Double.valueOf(fp.getFpjine().toString()), 
    					Double.valueOf(1+(Double.parseDouble(fp.getFpsl())/100)),2),(DecimalCalculateUtil.div(Double.parseDouble(fp.getFpsl()),100,2)));
    			
    			rep.setDkse(String.valueOf(dkse));//抵扣税额
    			rep.setHej(String.valueOf(fp.getFpjine()));//合计
    			heje+=Double.parseDouble(fp.getFpjine().toString());
    			replis.add(rep);
        	}
        	
//        	mmap.put("replis", replis);
//        	mmap.put("gsmc", gsmc);
//        	mmap.put("sbh", sbh);
//        	mmap.put("riq", new Date());
//        	mmap.put("heje", heje);
//        	mmap.put("hejedx", ConvertUpMoneyUtil.toChinese(String.valueOf(heje)));
//        	mmap.put("kj", "");
//        	mmap.put("zjl", "");
//        	mmap.put("head", DateUtils.dateTimeNow(DateUtils.YYYY)+"年"+DateUtils.dateTimeNow(DateUtils.MM)+"月");
        	
    	}
    	
        ExcelUtil<GcProjectExeVo> util = new ExcelUtil<GcProjectExeVo>(GcProjectExeVo.class);
        return util.exportExcel(replis, "项目结算数据");
    }
    
    /**
     * 结算清单
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/projectJsqd/{id}")
    public String projectJsqd(@PathVariable("id") Long id, ModelMap mmap){
    	GcProject gcProject = gcProjectService.selectGcProjectById(id);
        mmap.put("gcProject", gcProject);
        
        GcProjectXmxq gcProjectXmxq = new GcProjectXmxq();
        gcProjectXmxq.setDeleteFlag(1);
        gcProjectXmxq.setGcProjectid(id);
        List<GcProjectXmxq> xmxq = gcProjectXmxqService.selectGcProjectXmxqList(gcProjectXmxq);
        mmap.put("xmxq", xmxq.size()>0?xmxq.get(0):new GcProjectXmxq());
        
        //结算金额
        double fkje = 0.0;
        GcProjectQrsk qrsk = new GcProjectQrsk();
        qrsk.setGcProjectid(id);
        qrsk.setDeleteFlag(1);
        List<GcProjectQrsk> gcfklis = gcProjectQrskService.selectGcProjectQrskList(qrsk);
        List<Map> jsjelis = new ArrayList<Map>();
        for(GcProjectQrsk obj:gcfklis){
        	Map rep = new HashMap();
        	rep.put("je", obj.getQrjine());
        	rep.put("at", DateUtils.dateTime(obj.getSkAt()));
        	jsjelis.add(rep);
        	
        	fkje = DecimalCalculateUtil.add(fkje, obj.getQrjine());
        }
        //明目
        if(jsjelis==null || jsjelis.size()==0){
        	for(int i=0;i<10;i++){
        		Map rep = new HashMap();
        		rep.put("je", "");
            	rep.put("at", "");
            	jsjelis.add(rep);
        	}
        }else{
        	for(int i=jsjelis.size();i<10;i++){
        		Map rep = new HashMap();
        		rep.put("je", "");
            	rep.put("at", "");
            	jsjelis.add(rep);
        	}
        }
        
        //销项发票金额
        double xxfphj = 0.0;
        GcProjectSqkp gcProjectSqkp = new GcProjectSqkp();
        gcProjectSqkp.setGcProjectid(id);
        gcProjectSqkp.setDeleteFlag(1);
        List<GcProjectSqkp> gcProjectSqkplis = gcProjectSqkpService.selectGcProjectSqkpList(gcProjectSqkp);
        List<Map> xxfplis = new ArrayList<Map>();
        
        for(GcProjectSqkp obj:gcProjectSqkplis){
        	Map rep = new HashMap();
        	rep.put("je", obj.getItemje());
        	rep.put("at", DateUtils.dateTime(obj.getSqsj()));
        	xxfplis.add(rep);
        	xxfphj = DecimalCalculateUtil.add(xxfphj, Double.valueOf(obj.getItemje().toString()));
        }
        //明目
        if(xxfplis==null || xxfplis.size()==0){
        	for(int i=0;i<10;i++){
        		Map rep = new HashMap();
        		rep.put("je", "");
            	rep.put("at", "");
            	xxfplis.add(rep);
        	}
        }else{
        	for(int i=xxfplis.size();i<10;i++){
        		Map rep = new HashMap();
        		rep.put("je", "");
            	rep.put("at", "");
            	xxfplis.add(rep);
        	}
        }
        
        mmap.put("jsjelis", jsjelis);//结算金额
        mmap.put("fkje", fkje);//结算金额合计
        mmap.put("xxfplis", xxfplis);//销项发票金额
        mmap.put("xxfphj", xxfphj);//销项发票合计
        
        List<Map> detaillis = new ArrayList<Map>();//明目列表
        double xxkdkse = 0.0;//可抵扣税额
        double fkhjje = 0.0;//付款合计金额
        double kphjje = 0.0;//开票合计金额
        
        List<GcFkfp> fkfplis = gcFkfpService.selectGcFkfpSupplylis(id);
        
        for(GcFkfp fp:fkfplis){
        	GcFkfp gcFkfp = new GcFkfp();
            gcFkfp.setDeleteFlag(1);
            gcFkfp.setGcProjectid(id);
            gcFkfp.setCkdw(fp.getCkdw());
            List<GcFkfp> fplis = gcFkfpService.selectGcFkfpList(gcFkfp);
            
            GcFk gcFk = new GcFk();
            gcFk.setDeleteFlag(1);
            gcFk.setGcProjectid(id);
            gcFk.setCkdw(fp.getCkdw());
            List<GcFk> fklis = gcFkService.selectGcFkList(gcFk);
            
            if(fplis.size()==0 && fklis.size()==0){
            	returnDetailLis(0l,"", "", "", "", "", "", "", "", "", "");
            }else if(fplis.size()>fklis.size()){
            	for(int i=0;i<fplis.size();i++){
            		
            		String zfsj = "";
            		String zfje = "0";
            		String cbbl = "";
            		String descs = "";
            		String skdw = "";
            		Long fkId = -1l;
            		try {
            			zfsj = DateUtils.dateTime(fklis.get(i).getRiq());
                		zfje = fklis.get(i).getLjzf().toString();
                		cbbl = "";
                		descs = "";
                		skdw = fklis.get(i).getCkdw();
                		fkId = fklis.get(i).getId();
    				} catch (Exception e) {
    				}
            		
            		String kpsj = DateUtils.dateTime(fplis.get(i).getFpriq());
            		String kplx = fplis.get(i).getFpType();
            		String kpsl = fplis.get(i).getFpsl()+"%";
            		String kpje = fplis.get(i).getFpjine().toString();
            		String kdkse = fplis.get(i).getKdkse()==null?"0":fplis.get(i).getKdkse().toString();
            		
            		Map rep = returnDetailLis(fkId, zfsj, zfje, cbbl, descs, skdw, kpsj, kplx, kpsl, kpje, kdkse);
            		detaillis.add(rep);
            		xxkdkse = DecimalCalculateUtil.add(xxkdkse, Double.valueOf(kdkse));
            		fkhjje = DecimalCalculateUtil.add(fkhjje, Double.valueOf(zfje));
            		kphjje = DecimalCalculateUtil.add(kphjje, Double.valueOf(kpje));
            	}
            }else if(fplis.size()<fklis.size()){
            	for(int i=0;i<fklis.size();i++){
            		
            		String zfsj = DateUtils.dateTime(fklis.get(i).getRiq());
            		String zfje = fklis.get(i).getLjzf().toString();
            		String cbbl = "";
            		String descs = "";
            		String skdw = fklis.get(i).getCkdw();
            		String kpsj = "";
            		String kplx = "";
            		String kpsl = "";
            		String kpje = "0";
            		String kdkse = "0";
            		try {
            			kpsj = DateUtils.dateTime(fplis.get(i).getFpriq());
                		kplx = fplis.get(i).getFpType();
                		kpsl = fplis.get(i).getFpsl()+"%";
                		kpje = fplis.get(i).getFpjine().toString();
                		kdkse = fplis.get(i).getKdkse()==null?"0":fplis.get(i).getKdkse().toString();
    				} catch (Exception e) {
    				}
            		
            		Map rep = returnDetailLis(fklis.get(i).getId(),zfsj, zfje, cbbl, descs, skdw, kpsj, kplx, kpsl, kpje, kdkse);
            		detaillis.add(rep);
            		xxkdkse = DecimalCalculateUtil.add(xxkdkse, Double.valueOf(kdkse));
            		fkhjje = DecimalCalculateUtil.add(fkhjje, Double.valueOf(zfje));
            		kphjje = DecimalCalculateUtil.add(kphjje, Double.valueOf(kpje));
            	}
            }else if(fplis.size()==fklis.size()){
            	for(int i=0;i<fklis.size();i++){
            		String zfsj = DateUtils.dateTime(fklis.get(i).getRiq());
            		String zfje = fklis.get(i).getLjzf().toString();
            		String cbbl = "";
            		String descs = "";
            		String skdw = fklis.get(i).getCkdw();
            		String kpsj = DateUtils.dateTime(fplis.get(i).getFpriq());
            		String kplx = fplis.get(i).getFpType();
            		String kpsl = fplis.get(i).getFpsl()+"%";
            		String kpje = fplis.get(i).getFpjine().toString();
            		String kdkse = fplis.get(i).getKdkse()==null?"0":fplis.get(i).getKdkse().toString();
            		
            		Map rep = returnDetailLis(fklis.get(i).getId(),zfsj, zfje, cbbl, descs, skdw, kpsj, kplx, kpsl, kpje, kdkse);
            		detaillis.add(rep);
            		xxkdkse = DecimalCalculateUtil.add(xxkdkse, Double.valueOf(kdkse));
            		fkhjje = DecimalCalculateUtil.add(fkhjje, Double.valueOf(zfje));
            		kphjje = DecimalCalculateUtil.add(kphjje, Double.valueOf(kpje));
            	}
            }
        }
        
        mmap.put("detaillis", detaillis);//明目项
        mmap.put("xxkdkse", xxkdkse);//可抵扣税额
    	mmap.put("fkhjje", fkhjje);//付款合计金额
    	mmap.put("kphjje", kphjje);//开票合计金额
    	mmap.put("years", DateUtils.dateTimeNow(DateUtils.YYYY));
        return prefix + "/projectJsqd";
    }
    
    private Map returnDetailLis(Long fkId,String zfsj,String zfje,String cbbl,String descs,
    		String skdw,String kpsj,String kplx,String kpsl,String kpje,String kdkse){
    	
    	Map det = new HashMap();
    	det.put("zfsj", zfsj);//支付时间
    	det.put("zfje", zfje);//支付金额
    	det.put("cbbl", cbbl);//成本比例	
    	
    	det.put("skdw", skdw);//收款单位
    	det.put("kpsj", kpsj);//开票时间
    	det.put("kplx", kplx);//开票类型
    	det.put("kpsl", kpsl);//发票税率
    	det.put("kpje", kpje);//开票金额
    	det.put("kdkse", kdkse);//可抵扣税额
    	
    	GcFkitem gcFkitem = new GcFkitem();
    	gcFkitem.setFkId(fkId);
    	List<GcFkitem> fkItems = gcFkitemService.selectGcFkitemList(gcFkitem);
    	if(fkItems!=null && fkItems.size()>0){
    		det.put("descs", fkItems.get(0).getDescs());//付款事项摘要说明
    	}else{
    		det.put("descs", "");//付款事项摘要说明
    	}
    	
		return det;
    }
    
    /**
     * 修改项目时间
     * @param id
     * @param mmap
     * @return
     */
//    @RequiresPermissions("gcgl:project:projectUpAt")
    @GetMapping("/projectUpAt/{id}")
    public String projectUpAt(@PathVariable("id") Long id, ModelMap mmap){
    	//项目--验收时间
    	GcProject gcProject = gcProjectService.selectGcProjectById(id);
    	//项目合同
    	GcProjectXmxq gcProjectXmxq = new GcProjectXmxq();
    	gcProjectXmxq.setGcProjectid(id);
    	gcProjectXmxq.setDeleteFlag(1);
    	List<GcProjectXmxq> xmxqlis = gcProjectXmxqService.selectGcProjectXmxqList(gcProjectXmxq);
    	//项目成本评估
    	GcProjectCbpj gcProjectCbpj = new GcProjectCbpj();
    	gcProjectCbpj.setDeleteFlag(1);
    	gcProjectCbpj.setGcProjectid(id);
    	List<GcProjectCbpj> cbpjlis = gcProjectCbpjService.selectGcProjectCbpjList(gcProjectCbpj);
    	//分包三合同
    	GcProjectSgazht gcProjectSgazht = new GcProjectSgazht();
    	gcProjectSgazht.setDeleteFlag(1);
    	gcProjectSgazht.setGcProjectid(id);
    	List<GcProjectSgazht> sgazhtlis = gcProjectSgazhtService.selectGcProjectSgazhtList(gcProjectSgazht);
    	
    	GcProjectSbclht gcProjectSbclht = new GcProjectSbclht();
    	gcProjectSbclht.setDeleteFlag(1);
    	gcProjectSbclht.setGcProjectid(id);
    	List<GcProjectSbclht> sbclhtlis = gcProjectSbclhtService.selectGcProjectSbclhtList(gcProjectSbclht);
    	
    	GcProjectOther gcProjectOther = new GcProjectOther();
    	gcProjectOther.setDeleteFlag(1);
    	gcProjectOther.setGcProjectid(id);
    	List<GcProjectOther> otherlis = gcProjectOtherService.selectGcProjectOtherList(gcProjectOther);
    	
    	
    	SysDictData dictData = new SysDictData();
    	dictData.setDictType("gcgl_zf_type");
    	dictData.setStatus("0");
    	List<SysDictData> datelis = sysDictDataService.selectDictDataList(dictData);
    	
    	//款项支付
    	GcFk gcFk = new GcFk();
    	gcFk.setDeleteFlag(1);
    	gcFk.setGcProjectid(id);
    	List<GcFk> fklis = gcFkService.selectGcFkList(gcFk);
    	for(GcFk fk:fklis){
//    		fpType
    		for(SysDictData dd:datelis){
    			if(fk.getXmtype().toString().equals(dd.getDictValue())){
    				fk.setFpType(dd.getDictLabel());
    			}
    		}
    	}
    	
    	//进项发票
    	GcFkfp gcFkfp = new GcFkfp();
    	gcFkfp.setDeleteFlag(1);
    	gcFkfp.setGcProjectid(id);
    	List<GcFkfp> fkfplis = gcFkfpService.selectGcFkfpList(gcFkfp);
    	for(GcFkfp fkfp:fkfplis){
//    		fpType
    		for(SysDictData dd:datelis){
    			if(fkfp.getXmtype().toString().equals(dd.getDictValue())){
    				fkfp.setFpType(dd.getDictLabel());
    			}
    		}
    	}
    	
    	//申请开票
    	GcProjectSqkp gcProjectSqkp = new GcProjectSqkp();
    	gcProjectSqkp.setDeleteFlag(1);
    	gcProjectSqkp.setGcProjectid(id);
    	List<GcProjectSqkp> sqkplis = gcProjectSqkpService.selectGcProjectSqkpList(gcProjectSqkp);
    	
    	//销项发票
    	GcProjectSqkpfp gcProjectSqkpfp = new GcProjectSqkpfp();
    	gcProjectSqkpfp.setDeleteFlag(1);
    	gcProjectSqkpfp.setGcProjectid(id);
    	List<GcProjectSqkpfp> sqkpfplis = gcProjectSqkpfpService.selectGcProjectSqkpfpList(gcProjectSqkpfp);
    	
    	//确认收款
    	GcProjectQrsk gcProjectQrsk = new GcProjectQrsk();
    	gcProjectQrsk.setGcProjectid(id);
    	gcProjectQrsk.setDeleteFlag(1);
    	List<GcProjectQrsk> qrskList = gcProjectQrskService.selectGcProjectQrskList(gcProjectQrsk);
    	
    	mmap.put("gcProject", gcProject);
    	mmap.put("xmxq", xmxqlis.get(0));
    	mmap.put("cbpj", cbpjlis.get(0));
    	mmap.put("sgazhtlis", sgazhtlis);
    	mmap.put("sbclhtlis", sbclhtlis);
    	mmap.put("otherlis", otherlis);
    	mmap.put("fklis", fklis);
    	mmap.put("fkfplis", fkfplis);
    	mmap.put("sqkplis", sqkplis);
    	mmap.put("sqkpfplis", sqkpfplis);
    	mmap.put("qrskList", qrskList);
    	
    	return prefix + "/projectUpAt";
    }
    
    @Log(title = "项目立项", businessType = BusinessType.UPDATE)
    @PostMapping("/saveGcProjectUpVo")
    @ResponseBody
    public AjaxResult editSaveGcProjectUpVo(GcProjectUpVo gcProjectUpVo){
    	
    	try {
    		//验收时间
        	GcProject gcProject = new GcProject();
        	gcProject.setId(gcProjectUpVo.getGcProjectId());
        	gcProject.setUpdateAt(DateUtils.parseDate(gcProjectUpVo.getGcProjectupdateAt()));
        	gcProjectService.updateGcProject(gcProject);
        	//项目合同
        	GcProjectXmxq gcProjectXmxq = new GcProjectXmxq();
        	gcProjectXmxq.setId(gcProjectUpVo.getXmxqId());
        	gcProjectXmxq.setUpdateAt(DateUtils.parseDate(gcProjectUpVo.getXmxqupdateAt()));
        	gcProjectXmxq.setRiq(DateUtils.parseDate(gcProjectUpVo.getXmxqriq()));
        	gcProjectXmxqService.updateGcProjectXmxq(gcProjectXmxq);
        	//项目成本评估
        	GcProjectCbpj gcProjectCbpj = new GcProjectCbpj();
        	gcProjectCbpj.setGcProjectid(gcProjectUpVo.getGcProjectId());
        	gcProjectCbpj.setPgsj(DateUtils.parseDate(gcProjectUpVo.getPgsj()));
        	gcProjectCbpjService.updateGcProjectCbpj(gcProjectCbpj);
        	//分包三合同————设备材料合同
        	if(gcProjectUpVo.getSbclhtId()!=null && gcProjectUpVo.getSbclhtId().size()>0){
        		for(int i=0;i<gcProjectUpVo.getSbclhtId().size();i++){
            		GcProjectSbclht gcProjectSbclht = new GcProjectSbclht();
                	gcProjectSbclht.setId(gcProjectUpVo.getSbclhtId().get(i));
                	gcProjectSbclht.setCreateAt(DateUtils.parseDate(gcProjectUpVo.getSbclhtcreateAt().get(i)));
                	gcProjectSbclhtService.updateGcProjectSbclht(gcProjectSbclht);
            	}
        	}
        	
        	//施工安装合同
        	if(gcProjectUpVo.getSgazhtId()!=null && gcProjectUpVo.getSgazhtId().size()>0){
        		for(int i=0;i<gcProjectUpVo.getSgazhtId().size();i++){
        	    	GcProjectSgazht gcProjectSgazht = new GcProjectSgazht();
        	    	gcProjectSgazht.setId(gcProjectUpVo.getSgazhtId().get(i));
        	    	gcProjectSgazht.setCreateAt(DateUtils.parseDate(gcProjectUpVo.getSgazhtcreateAt().get(i)));
        	    	gcProjectSgazhtService.updateGcProjectSgazht(gcProjectSgazht);
            	}
        	}
        	
        	//工程其它合同
        	if(gcProjectUpVo.getOtherId()!=null && gcProjectUpVo.getOtherId().size()>0){
	        	for(int i=0;i<gcProjectUpVo.getOtherId().size();i++){
	    	    	GcProjectOther gcProjectOther = new GcProjectOther();
	    	    	gcProjectOther.setId(gcProjectUpVo.getOtherId().get(i));
	    	    	gcProjectOther.setCreateAt(DateUtils.parseDate(gcProjectUpVo.getOthercreateAt().get(i)));
	    	    	gcProjectOtherService.updateGcProjectOther(gcProjectOther);
	        	}
        	}
        	//款项支付
        	for(int i=0;i<gcProjectUpVo.getFkId().size();i++){
        		GcFk gcFk = new GcFk();
        		gcFk.setId(gcProjectUpVo.getFkId().get(i));
        		gcFk.setRiq(DateUtils.parseDate(gcProjectUpVo.getFkriq().get(i)));
        		gcFkService.updateGcFk(gcFk);
        	}
        	//进项发票
        	for(int i=0;i<gcProjectUpVo.getFkfpId().size();i++){
        		GcFkfp gcFkfp = new GcFkfp();
        		gcFkfp.setId(gcProjectUpVo.getFkfpId().get(i));
        		gcFkfp.setFpriq(DateUtils.parseDate(gcProjectUpVo.getFkfpriq().get(i)));
        		gcFkfpService.updateGcFkfp(gcFkfp);
        	}
        	//申请开票
        	for(int i=0;i<gcProjectUpVo.getSqkpId().size();i++){
        		GcProjectSqkp gcProjectSqkp = new GcProjectSqkp();
        		gcProjectSqkp.setId(gcProjectUpVo.getSqkpId().get(i));
        		gcProjectSqkp.setSqsj(DateUtils.parseDate(gcProjectUpVo.getSqkpsqsj().get(i)));
        		gcProjectSqkpService.updateGcProjectSqkp(gcProjectSqkp);
        	}
        	//销项发票
        	for(int i=0;i<gcProjectUpVo.getSqkpfpId().size();i++){
        		GcProjectSqkpfp gcProjectSqkpfp = new GcProjectSqkpfp();
        		gcProjectSqkpfp.setId(gcProjectUpVo.getSqkpfpId().get(i));
        		gcProjectSqkpfp.setFpriq(DateUtils.parseDate(gcProjectUpVo.getSqkpfpriq().get(i)));
        		gcProjectSqkpfpService.updateGcProjectSqkpfp(gcProjectSqkpfp);
        	}
        	//确认收款
        	for(int i=0;i<gcProjectUpVo.getQrskId().size();i++){
        		GcProjectQrsk gcProjectQrsk = new GcProjectQrsk();
        		gcProjectQrsk.setId(gcProjectUpVo.getQrskId().get(i));
        		gcProjectQrsk.setSkAt(DateUtils.parseDate(gcProjectUpVo.getQrskAt().get(i)));
        		gcProjectQrskService.updateGcProjectQrsk(gcProjectQrsk);
        	}
		} catch (Exception e) {
			// TODO: handle exception
			e.getLocalizedMessage();
			toAjax(0);
		}
    	
    	return toAjax(1);
    }
}